package com.ywq.app.biz.impl;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.Transactional;

import com.ywq.app.biz.ArtActivityBiz;
import com.ywq.app.biz.ArtPicBiz;
import com.ywq.app.biz.IdentifierBiz;
import com.ywq.app.biz.MailBiz;
import com.ywq.app.biz.MemberBiz;
import com.ywq.app.dao.MemberDao;
import com.ywq.app.domain.ArtActivity;
import com.ywq.app.domain.ArtAuction;
import com.ywq.app.domain.ArtBack;
import com.ywq.app.domain.ArtClass;
import com.ywq.app.domain.ArtOrders;
import com.ywq.app.domain.ArtProcessLog;
import com.ywq.app.domain.ArtRoom;
import com.ywq.app.domain.Member;
import com.ywq.app.domain.MemberAddress;
import com.ywq.app.domain.MemberBank;
import com.ywq.app.domain.MemberHas;
import com.ywq.app.domain.MemberHobby;
import com.ywq.app.domain.MemberSecurity;
import com.ywq.app.domain.OnLineUserListener;
import com.ywq.common.constant.PageSize;
import com.ywq.common.exception.AppBusinessException;
import com.ywq.common.page.PageModel;
import com.ywq.common.util.Common;
import com.ywq.common.util.IdGenerator;





public class MemberBizImpl implements MemberBiz{
	
	private final static Logger logger = LoggerFactory
	.getLogger(MemberBizImpl.class);

	private MemberDao memberDao;
	
	
	@Autowired
	private IdentifierBiz idBiz;
	@Autowired
	private MailBiz mailBiz;
	@Autowired
	private ArtActivityBiz artActivityBiz;
	
	@Autowired
	private ArtPicBiz artPicBiz;
	
	private DataSourceTransactionManager transactionManager;

	public void setTransactionManager(
			DataSourceTransactionManager transactionManager) {
		this.transactionManager = transactionManager;
	}
	
	public void setMemberDao(MemberDao memberDao) {
		this.memberDao = memberDao;
	}
	/**
	 * 注册
	 * @param 
	 * @return
	 * @throws
	 */
	@Transactional(rollbackForClassName = { "cn.sumpu.app.coolsk.exception.AppBusinessException" }, timeout = 10)
	public Member register(String emailPath,Member member) throws AppBusinessException {
		 member.setId(idBiz.generateId("art_member"));//会员号 
		 member.setActiveCode(Common.getRandStr(10, false));//邮箱激活码
		 //member.setIsActive(true);//激活邮箱
		 String salt=Common.getRandStr(6, false);
		 member.setSalt(salt);//密码MD5加密辅助字段
		 String passWord = member.getPassword();
		 member.setPassword(Common.md5(Common.md5(passWord)));
		 member.setAvatar(PageSize.AVATAR_MEMBER_DEFALUT);
		// regOutUser(member);  
		 memberDao.insert(member);
		mailBiz.sendEmail(emailPath, member,null,null);
		return member;
	}


	/**
	 * 用户登陆
	 * @
	 * @
	 * @param  
     * @return
	 * @throws
	 */
	@Override
	public Member IsRegister(String loginType,String loginPwd)throws AppBusinessException {
		if (Common.empty(loginType))
			return null;
		//昵称 
		Member member = getMemberByNick(loginPwd, loginType);
		//邮箱
		if (member == null) {
			member = getMemberByEmail(loginPwd, loginType);
		}
		// 手机号码
		if (member== null) {
			member= getMemberByPhone(loginPwd, loginType);
		}
		return member;
	}
	/**
	 * 登录
	 * @author 
	 * @param
	 * @param
	 */
	@Override
	public String login(HttpServletRequest request,HttpServletResponse response) throws AppBusinessException {
		String loginName = request.getParameter("loginName");  
		String loginPwd = request.getParameter("loginPwd");
		String autoLogin = request.getParameter("autoLogin");
		String outLoginMember = request.getParameter("om");
		try {
			// 从cookie里面直接登录
			String cookieLogin = (String) request.getSession().getAttribute("cookieLogin");
			if (Common.notEmptyStr(cookieLogin)) {
				loginName = (String) request.getSession().getAttribute("loginName");
				loginPwd = (String) request.getSession().getAttribute("loginPwd");
				request.getSession().removeAttribute("loginType");
				request.getSession().removeAttribute("loginPwd");
				request.getSession().removeAttribute("cookieLogin");
			}
			// 设置cookie
			setLoginCookie(loginName, loginPwd, autoLogin, response);
			Member  member=null;
			if(Common.notEmptyStr(outLoginMember)){
				member=getMemberById(outLoginMember);
			}else{
				member = IsRegister(loginName, loginPwd); // 是否注册会员
			} 
			if (member != null && member.getEnabled()) {
				//Date loginTime=member.getLoginTime();
				//String nowTime = Common.getFormatDate(Calendar.getInstance().getTime(), "yyyy-MM-dd");
				//SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 
				//Date nowDate = sdf.parse(nowTime);
				//Boolean isTrue =nowDate.after(loginTime);
				/*if(isTrue){
					
					int pVal=5;
					member.setCountPoint(member.getCountPoint()+pVal);
	
					String remark="";
					
				}*/
				member.setLoginIP(request.getRemoteAddr());
				member.setLoginTime(new Date());// 设置最后登录的时间
				update(member);// 设置最后登录的IP
				request.getSession(true).setAttribute("onlineUser",
						new OnLineUserListener(member));
				return "dailylogin";
			}else{
				return "noRegister";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	/**
	 *  存储Cookie
	 * @param loginName
	 * @param loginPwd
	 * @param autoLogin
	 * @param response
	 * @throws UnsupportedEncodingException
	 */
	private void setLoginCookie(String loginName, String loginPwd, String autoLogin, HttpServletResponse response) throws UnsupportedEncodingException {
		if (Common.notEmptyStr(autoLogin)) {
			Cookie cookieLoginName = new Cookie("art_user_loginName",
					URLEncoder.encode(loginName, "utf-8"));
			Cookie cookieLoginPwd = new Cookie("art_user_loginPwd",
					URLEncoder.encode(loginPwd, "utf-8"));
			cookieLoginName.setMaxAge(60 * 60 * 24 * 30); // 一个月有效
			cookieLoginPwd.setMaxAge(60 * 60 * 24 * 30); // 一个月有效
			response.addCookie(cookieLoginName);
			response.addCookie(cookieLoginPwd);
		}
	}
	/**
	 * 昵称登录
	 * @
	 * @
	 * @param  
     * @return
	 * @throws
	 */
	@Override
	public Member getMemberByNick(String pwd, String nickname)throws AppBusinessException {
		if (Common.empty(nickname))
			return null; 
		pwd = Common.md5(Common.md5(pwd));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("password", pwd);
		map.put("nickname", nickname);
		Member member = memberDao.getMemberByMap(map);
		return member;
	}
	/**
	 * 邮箱登录
	 * @
	 * @
	 * @param  
     * @return
	 * @throws
	 */
	@Override
	public Member getMemberByEmail(String pwd, String email)throws AppBusinessException {
		if (Common.empty(email))
			return null;
		pwd = Common.md5(Common.md5(pwd));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("password", pwd);
		map.put("email", email);
		Member member = memberDao.getMemberByMap(map);
		return member;
	}
	/**
	 * 手机登录
	 * @
	 * @
	 * @param  
     * @return
	 * @throws
	 */
	@Override
	public Member getMemberByPhone(String pwd, String phone)throws AppBusinessException {
		if (Common.empty(phone))
			return null;
		pwd = Common.md5(Common.md5(pwd));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("password", pwd);
		map.put("mobilephone", phone);
		Member member = memberDao.getMemberByMap(map);
		return member;
	}
	/**
	 * 更新会员信息
	 * @
	 * @
	 * @param  
     * @return
	 * @throws
	 */
	@Override
	public void update(Member member)throws AppBusinessException {
		memberDao.update(member);
	}
	@Override
	public void updateSecurityMoney(Member member)throws AppBusinessException {
		System.out.println("member————————————————————————————————————————————————member"+member.getArtAccount());
		memberDao.updateSecurityMoney(member);
	}
	
	@Override
	public void updateMemberEnabled(String id)throws AppBusinessException {
		memberDao.updateMemberEnabled(id);
	}
	
	@Override
	public void updateResetAccount(String id, float artAccount)throws AppBusinessException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		map.put("artAccount", artAccount);
		memberDao.updateResetAccount(map);
	}
	
	
	/**
	 * 验证邮箱 [注册]
	 * @
	 * @
	 * @param  
     * @return
	 * @throws
	 */
	
	@Override
	public Member getMemberEmail(String email)throws AppBusinessException {
		if (Common.empty(email))
			return null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("email", email);
		Member member = memberDao.getMemberByMap(map);
		return member;
	}
	/**
	 * 验证昵称 [注册]
	 * @
	 * @
	 * @param  
     * @return
	 * @throws
	 */
	
	@Override
	public Member getMemberNickName(String nickname)throws AppBusinessException {
		if (Common.empty(nickname))
			return null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("nickname", nickname);
		Member member = memberDao.getMemberByMap(map);
		return member;
	}
	/**
	 * 验证手机[注册]
	 * @
	 * @
	 * @param  
     * @return
	 * @throws
	 */
	@Override
	public Member getMemberPhone(String phone)throws AppBusinessException {
		if (Common.empty(phone))
			return null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("mobilephone", phone);
		Member member = memberDao.getMemberByMap(map);
		return member;
	}

	

	@Override
	public Member getMemberById(String member) throws AppBusinessException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", member); 
		return memberDao.getMemberByMap(map);
	}

	@Override
	public Boolean checkMemberLogin(HttpServletRequest request)
			throws AppBusinessException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Integer getMemberListCount(String nickname, String startTime,
			String endTime) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	//得到会员的订单
	@Override
	public List<ArtOrders> getOrdersListByMemberId(Map<String,Object> map) throws Exception {
		return	memberDao.getOrdersListByMemberId(map);
	}
	//分页  会员所有订单
	@Override
	public PageModel getOrdersById(Integer page,String memberId,String type) throws AppBusinessException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("startId", (page - 1) * PageSize.PAGE_SIZE_ORDERS);
		map.put("pageSize", PageSize.PAGE_SIZE_ORDERS);
		map.put("memberId", memberId);
		map.put("type", type);
		int count = memberDao.getOrdersByIdCount(map);
		PageModel pm = new PageModel();
		pm.setCurrentPage(page);
		List<ArtOrders> orderList =memberDao.getOrdersListByMemberId(map);
		if(orderList.size()>0){
			for(ArtOrders artOrder :orderList){
				Member member =getMemberById(artOrder.getMemberId());
				artOrder.setMemberName(member.getNickname());
			}
		}
		pm.setList(orderList);
		pm.setPageSize(PageSize.PAGE_SIZE_ORDERS);
		pm.setTotalRecord(count);
		pm.setTotalPage((count + PageSize.PAGE_SIZE_ORDERS - 1)
				/ PageSize.PAGE_SIZE_ORDERS);
		return pm;
	}
		//分页  活动所有列表
		@Override
		public PageModel getActivityById(Integer page, String memberId)throws AppBusinessException {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("startId", (page - 1) * PageSize.PAGE_SIZE_ACTIVITY);
			map.put("pageSize", PageSize.PAGE_SIZE_ACTIVITY);
			map.put("memberId", memberId);
			int count = memberDao.getActivityByIdCount(map);
			//List<ArtActivityMember>  myActivity =;
			//myActivity=formatTime(myActivity);
			PageModel pm = new PageModel();
			pm.setCurrentPage(page);
			pm.setList(memberDao.getActivityByMemberId(map));
			pm.setPageSize(PageSize.PAGE_SIZE_ACTIVITY);
			pm.setTotalRecord(count);
			pm.setTotalPage((count + PageSize.PAGE_SIZE_ACTIVITY - 1)
					/ PageSize.PAGE_SIZE_ACTIVITY);
			return pm;
		}
		// 格式化时间
		@Override
		public List<ArtActivity> formatTime(List<ArtActivity> aList) throws AppBusinessException {
			try {
				for (ArtActivity act : aList) {
					SimpleDateFormat secData = new SimpleDateFormat("yyyy-MM-dd");
					SimpleDateFormat secTime = new SimpleDateFormat("HH:mm:ss");
					Date sDate = secData.parse(act.getStartDate());
					Date eDate = secData.parse(act.getEndDate());
					Date sTime = secTime.parse(act.getStartTime());
					Date eTime = secTime.parse(act.getEndTime());
					act.setsDate(sDate);
					act.seteDate(eDate);
					act.setsTime(sTime);
					act.seteTime(eTime);
				}
			} catch (ParseException e) {
				e.printStackTrace();
			}
			return aList;
		}
		//Has 新增
		@Override
		public void insertMemberHas(MemberHas memberHas ) throws AppBusinessException {
			//String id = IdGenerator.createIdentifier();
			String id = idBiz.generateId("art_orders");
			memberHas.setId(id);
			memberDao.insertMemberHas(memberHas);
		}
		//取消喜欢
		@Override
		public void deleteMemberHas(String hasId ) throws AppBusinessException {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("id", hasId);
			memberDao.deleteMemberHas(map);
		}
		//查看是否存在
		public List<MemberHas>getHasList(Map<String, Object> map)throws AppBusinessException {
			List<MemberHas> mHasList =memberDao.getHasList(map);
				if(mHasList.size()>0){
					for(MemberHas mHas :mHasList){
						//ArtClass artClass =
						ArtClass artClass=artPicBiz.getClassById(mHas.getArtPic().getArtClass());
						if(artClass!=null){
							mHas.getArtPic().setArtClassName(artClass.getName());
						}
					}
				}
			return mHasList;
		}
		
		//取消活动
		@Transactional(rollbackForClassName = {"com.ywq.common.exception.AppBusinessException;"}, timeout = 10)
		@Override
		public void noJoinActivity(String acId ,String memberId) throws AppBusinessException {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("activityId", acId);
			map.put("memberId", memberId);
			memberDao.noJoinActivity(map);
			ArtActivity artActivity  =artActivityBiz.getArtActivityById(acId);
			artActivity.setSignNum(artActivity.getSignNum()-1);
			artActivityBiz.updateArtActivity(artActivity);
			
			
		}
		//锁定账号
		@Override
		public void unLockAccount(String memberId)throws AppBusinessException {
			Member member =new Member();
			member.setId(memberId);
			member.setIsAccount(false);
			memberDao.update(member);
		}
		//解锁账号
		@Override
		public void lockAccount(String memberId)throws AppBusinessException {
			Member member =new Member();
			member.setId(memberId);
			member.setIsAccount(true);
			memberDao.update(member);
		}
		//增加银行账号
		@Override
		public void insertMemberBank(MemberBank memberBank)throws AppBusinessException {
			String id = idBiz.generateId("member_bank");
			memberBank.setId(id);
			memberDao.insertMemberBank(memberBank);
		}
		//取消所有默认账号
		@Override
		public void noAllBankDefault(String memberId)throws AppBusinessException {
			memberDao.noAllBankDefault(memberId);
		}
		
		//设置默认
		@Override
		public void updateBankDefault(String id)throws AppBusinessException {
			//新的默认账号
			MemberBank memberBank =new MemberBank();
			memberBank.setId(id);
			memberBank.setIsDefault(true);
			memberDao.updateBankDefault(memberBank);
		}
		
		//删除账号
		@Override
		public void deleteMemberBank(String bankId)throws AppBusinessException {
			memberDao.deleteMemberBank(bankId);
		}
		//银行账号列表
		public List<MemberBank> getBankLiatByMemberId(String memberId)throws AppBusinessException {
			return memberDao.getBankListByMemberId(memberId);
		}
		//增加收货地址
		@Override
		public void insertMemberAddress(MemberAddress memberAddress)throws AppBusinessException {
			String id = idBiz.generateId("member_address");
			memberAddress.setId(id);
			memberDao.insertMemberAddress(memberAddress);
		}
		//保存喜好
		@Override
		public void insertMemberHobby(MemberHobby memberHobby)throws AppBusinessException {
			memberDao.insertMemberHobby(memberHobby);
		}
		@Override
		public void deleteMemberHobby(String memberId)throws AppBusinessException {
			memberDao.deleteMemberHobby(memberId);
		}
		@Override
		public void deleteComment(String commentId)throws AppBusinessException {
			memberDao.deleteComment(commentId);
		}
		
		
		//查询收货地址
		@Override
		public List<MemberAddress> getAddressListByMemberId(String memberId)throws AppBusinessException {
			return memberDao.getAddressListByMemberId(memberId);
		}
		//更新收货地址
		@Override
		public void updateMemberAddress(MemberAddress memberAddress)throws AppBusinessException {
			memberDao.updateMemberAddress(memberAddress);
		}
		//查询地址详情
		@Override
		public MemberAddress getAddressByaId(String aId)throws AppBusinessException {
			return memberDao.getAddressByaId(aId);
		}
		//得到某一订单
		@Override
		public ArtOrders getOrdersById(String oid) throws AppBusinessException {
			return	memberDao.getOrdersById(oid);
		}
		//更新订单
		@Override
		public void updateOrders(Map<String, Object> map)throws AppBusinessException {
			//新的默认账号
			memberDao.updateOrders(map);
		}
		@Override
		public PageModel getMemberMode(Integer page,Integer pageSize,String name)throws AppBusinessException {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("startId", (page - 1) * pageSize);
			map.put("pageSize", pageSize);
			map.put("name", name);
			int count = memberDao.getMemberModeCount(map);
			//List<ArtActivityMember>  myActivity =;
			//myActivity=formatTime(myActivity);
			PageModel pm = new PageModel();
			pm.setCurrentPage(page);
			pm.setList(memberDao.getMemberMode(map));
			pm.setPageSize(pageSize);
			pm.setTotalRecord(count);
			pm.setTotalPage((count + pageSize - 1)
					/ pageSize);
			return pm;
		}
		//查询喜好
		@Override
		public List<MemberHobby> getHobbyListByMemberId(String memberId)throws AppBusinessException {
			return memberDao.getHobbyListByMemberId(memberId);
		}
		//付款成功
		@Override
		public void payAlipaySuc(String ordersId)throws AppBusinessException {
			ArtOrders order = getOrdersById(ordersId);
			if(order!=null){
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("ordersId", ordersId);
				map.put("isRead", true);
				memberDao.payAlipaySuc(map);
			}
		}
		//30天订单数
		@Override
		public int getCountThity(String memberId)throws AppBusinessException {
			return memberDao.getCountThity(memberId);
		}
		//新增会员保证金（提取/充值）
		@Override
		public void insertMemberSecurity(MemberSecurity memberSecurity ) throws AppBusinessException {
			//String id = IdGenerator.createIdentifier();
			String id = idBiz.generateId("art_orders");
			memberSecurity.setId("SY"+id);
			memberDao.insertMemberSecurity(memberSecurity);
			
		}
		//查询会员保证金（提取/充值）
		@Override
		public PageModel getMemberSecurity(Integer page,Integer pageSize)throws AppBusinessException {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("startId", (page - 1) * pageSize);
			map.put("pageSize", pageSize);
			map.put("type", "02");//提现
			int count = memberDao.getMemberSecurityCount(map);
			//List<ArtActivityMember>  myActivity =;
			//myActivity=formatTime(myActivity);
			PageModel pm = new PageModel();
			pm.setCurrentPage(page);
			List<MemberSecurity> memberSecurityList =memberDao.getMemberSecurity(map);
			if(memberSecurityList.size()>0){
				for(MemberSecurity memberSecurity :memberSecurityList){
					Member member =getMemberById(memberSecurity.getMemberId());
					memberSecurity.setMemberName(member.getNickname());
					memberSecurity.setAccountOld(member.getArtAccount());
				}
			}
			pm.setList(memberSecurityList);
			pm.setPageSize(pageSize);
			pm.setTotalRecord(count);
			pm.setTotalPage((count + pageSize - 1)/ pageSize);
			return pm;
		}
		//退货列表
		@Override
		public PageModel memberBackListGrid(Integer page,Integer pageSize)throws AppBusinessException {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("startId", (page - 1) * pageSize);
			map.put("pageSize", pageSize);
			map.put("backStatus", "01");
			int count = memberDao.memberBackListCount(map);
			PageModel pm = new PageModel();
			pm.setCurrentPage(page);
			pm.setList(memberDao.memberBackListGrid(map));
			pm.setPageSize(pageSize);
			pm.setTotalRecord(count);
			pm.setTotalPage((count + pageSize - 1)/ pageSize);
			return pm;
		}
		//充值
		@Override
		public String insertMemberPay(MemberSecurity memberSecurity ) throws AppBusinessException {
			//String id = IdGenerator.createIdentifier();
			String id = idBiz.generateId("art_orders");
			memberSecurity.setId("SY"+id);
			memberDao.insertMemberSecurity(memberSecurity);
			return memberSecurity.getId();
			
		}
		//得到某一订单
		@Override
		public MemberSecurity getMemberSecurity(String id) throws AppBusinessException {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("id", id);
			return	memberDao.getMemberSecurityById(map);
		}
		@Override
		public ArtBack getArtBackByOid(String oid) throws AppBusinessException {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("backId", oid);
			return	memberDao.getArtBackByOid(map);
		}
		
		//退货物流状态
		@Transactional(rollbackForClassName = { "cn.sumpu.app.art.exception.AppBusinessException" }, timeout = 10)
		@Override
		public void insertArtBack(ArtBack artBack ) throws AppBusinessException {
			String id = idBiz.generateId("art_back");
			artBack.setId("back"+id);
			artBack.setStatus("01");//未审核 02 拒绝 03是同意
			memberDao.insertArtBack(artBack);
			ArtProcessLog artProcessLog =new ArtProcessLog();
			 Member member = getMemberById(artBack.getMemberId());
			artProcessLog.setMemberName(member.getNickname());
			artProcessLog.setStatus(Common.BACK_TO_INFO);
			artProcessLog.setProcessId(id);
			artProcessLog.setProcessType("back");
			insertArtProcessLog(artProcessLog);
			
		}
		//审核退货订单（后台）
		@Transactional(rollbackForClassName = { "cn.sumpu.app.art.exception.AppBusinessException" }, timeout = 10)
		@Override
		public void updateArtBack(ArtBack artBack,ArtProcessLog artProcessLog) throws AppBusinessException {
			memberDao.updateArtBack(artBack);
			artProcessLog.setMemberName("管理员");
			artProcessLog.setProcessId(artBack.getBackId());
			artProcessLog.setProcessType("back");
			insertArtProcessLog(artProcessLog);
		}
		//添加退货
		@Transactional(rollbackForClassName = { "cn.sumpu.app.art.exception.AppBusinessException" }, timeout = 10)
		@Override
		public void insertBackLog(String id,String memberId)throws AppBusinessException{
			//更新原始订单状态：已申请
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("id", id);
			map.put("backStatus", "01");
		    updateOrders(map);
		    //生成新log
		    Member member = getMemberById(memberId);
		    if(member!=null){
		    	ArtProcessLog artProcessLog =new ArtProcessLog();
			    artProcessLog.setMemberName(member.getNickname());
			    artProcessLog.setContent("申请退货。");
			    artProcessLog.setStatus(Common.BACK_APPLICATION);
			    artProcessLog.setProcessId(id);
			    artProcessLog.setProcessType("back");
			    insertArtProcessLog(artProcessLog);
		    }
		}
		
		//退货日志
		@Override
		public void insertArtProcessLog(ArtProcessLog artProcessLog ) throws AppBusinessException {
			String id = idBiz.generateId("art_process_log");
			artProcessLog.setId("log"+id);
			memberDao.insertArtProcessLog(artProcessLog);
		}
		//日记列表
		@Override
		public List<ArtProcessLog> getProcessList(String id)throws AppBusinessException {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("processId", id);
			map.put("processType", "back");
			return memberDao.getProcessList(map);
		}
		@Override
		public ArtProcessLog getArtProcessLogByRef(String id,String status)throws AppBusinessException {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("processId", id);
			map.put("processType", "back");
			map.put("status", status);
			return memberDao.getArtProcessLogByRef(map);
		}
		//退货是否同意
		@Override
		public void updateBackOrders(String oId,String backStatus ,String content) throws AppBusinessException {
			ArtProcessLog artProcessLog =new ArtProcessLog();
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("id", oId);
			if(backStatus.equals("refusal")){
				artProcessLog.setContent(content);
				artProcessLog.setStatus(Common.BACK_REFUSAL);
				map.put("backStatus", "02");
			}else if(backStatus.equals("agree")){
				artProcessLog.setContent("同意退货。");
				artProcessLog.setStatus(Common.BACK_AGREE);
				map.put("backStatus", "03");
			}else if(backStatus.equals("pay")){
				artProcessLog.setContent("已付款。");
				artProcessLog.setStatus(Common.BACK_PAY);
				map.put("backStatus", "05");
			}
			updateOrders(map);
			artProcessLog.setMemberName("管理员");
			artProcessLog.setProcessId(oId);
			artProcessLog.setProcessType("back");
			insertArtProcessLog(artProcessLog);
		}
}
